package org.amicofragile.test.jbehave;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

public class PetAdoptionUseCase {
    private Map<String, Person> persons;
    private Map<String, Pet> pets;
    
    public PetAdoptionUseCase() {
	this.persons = new HashMap<String, Person>();
	this.pets = new HashMap<String, Pet>();
    }
    
    @Given("a person named $name")
    public void aPerson(final String name) {
	this.persons.put(name, new Person(name));
    }
    
    @Given("a pet named $name")
    public void aPet(final String petName) {
	this.pets.put(petName, new Pet(petName));
    }
    
    @When("$personName adopts $petName")
    public void aPersonAdoptsAPet(final String personName, final String petName) {
	this.persons.get(personName).addPet(this.pets.get(petName));
    }
    
    @Then("$personName owns $count pets")
    public void checkpersonPetCount(final String personName, final int count) {
	Assert.assertEquals("Wrong pets count", count, this.persons.get(personName).getPetsCount());
    }
}
